/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Arrays;
import java.util.Random;

/**
 * <p>Project: app2022 - ArrSort1
 * <p>Powered by webrx On 2022-01-08 16:26:29
 *
* @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class ArrSort4 {
    public static void main(String[] args) {
        //Student[] 数组
        var ss = new Student[]{new Student(1, "张三丰", 30), new Student(2, "李四", 66), new Student(3, "张三", 99), new Student(4, "王五", 80)};
        //未排序
        System.out.println(Arrays.toString(ss));

        //升序
        Arrays.sort(ss, (a, b) -> a.getScore() - b.getScore());
        System.out.println(Arrays.toString(ss));

        //降序
        Arrays.sort(ss, (a, b) -> b.getScore() - a.getScore());
        System.out.println(Arrays.toString(ss));

        //乱序
        var rand = new Random();
        for (int i = 0; i < 1000; i++) {
            int a = rand.nextInt(ss.length);
            int b = rand.nextInt(ss.length);
            if (a == b) continue;
            Student t = ss[a];
            ss[a] = ss[b];
            ss[b] = t;
        }
        System.out.println(Arrays.toString(ss));

    }
}
